#include "compile_run.hpp"
#include "../comm/httplib.h"
using namespace ns_compile_and_run;
using namespace httplib;

void Usage(const std::string &pro)
{
    std::cout << "Usage:" << "\n\t" << pro << " port" << std::endl;
}
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        return 1;
    }
    Server ser;
    ser.Post("/compile_and_run", [](const Request &req, Response &resp){
        std::string inJson = req.body;
        std::string outJson;
        if(!inJson.empty())
        {
            CompileAndRun::Start(inJson,&outJson);
            resp.set_content(outJson,"application/json;charset=utf-8");
        } 
    });
    ser.listen("0.0.0.0", atoi(argv[1]));
    // std::string in_json;
    // Json::Value in_value;
    // //R"()", raw string
    // in_value["code"] = R"(#include<iostream>
    // int main(){
    //     return 0;
    // })";
    // in_value["input"] = "";
    // in_value["cpu_limit"] = 1;
    // in_value["mem_limit"] = 10240*3;
    // Json::FastWriter writer;
    // in_json = writer.write(in_value);
    // std::cout << in_json << std::endl;
    // //这个是将来给客户端返回的json串
    // std::string out_json;
    // CompileAndRun::Start(in_json, &out_json);

    // std::cout << out_json << std::endl;
    return 0;
}